@@ -297,9 +297,7 @@ def consumer_info_api(request): |
||
297 | 297 |
verifyResult=1, |
298 | 298 |
test_user=False, |
299 | 299 |
).count() == 1: |
300 |
- ymd = int(tc.local_string(format='%Y%m%d')) |
|
301 |
- ym = int(tc.local_string(format='%Y%m')) |
|
302 |
- y = int(tc.local_string(format='%Y')) |
|
300 |
+ ymd = tc.local_string(format='%Y%m%d') |
|
303 | 301 |
|
304 | 302 |
# 日销量统计 |
305 | 303 |
ssi, _ = ConsumeSaleStatisticInfo.objects.select_for_update().get_or_create( |
@@ -311,14 +309,14 @@ def consumer_info_api(request): |
||
311 | 309 |
# 月销量统计 |
312 | 310 |
ssi, _ = ConsumeSaleStatisticInfo.objects.select_for_update().get_or_create( |
313 | 311 |
brand_id=brand.brand_id, |
314 |
- ymd=ym, |
|
312 |
+ ymd=ymd[:6], |
|
315 | 313 |
) |
316 | 314 |
ssi.num += 1 |
317 | 315 |
ssi.save() |
318 | 316 |
# 年销量统计 |
319 | 317 |
ssi, _ = ConsumeSaleStatisticInfo.objects.select_for_update().get_or_create( |
320 | 318 |
brand_id=brand.brand_id, |
321 |
- ymd=y, |
|
319 |
+ ymd=ymd[:4], |
|
322 | 320 |
) |
323 | 321 |
ssi.num += 1 |
324 | 322 |
ssi.save() |
@@ -336,7 +334,7 @@ def consumer_info_api(request): |
||
336 | 334 |
mssi, _ = ConsumeModelSaleStatisticInfo.objects.select_for_update().get_or_create( |
337 | 335 |
brand_id=brand.brand_id, |
338 | 336 |
model_id=model.model_id, |
339 |
- ymd=ym, |
|
337 |
+ ymd=ymd[:6], |
|
340 | 338 |
) |
341 | 339 |
mssi.model_name = model.model_name |
342 | 340 |
mssi.num += 1 |
@@ -345,7 +343,7 @@ def consumer_info_api(request): |
||
345 | 343 |
mssi, _ = ConsumeModelSaleStatisticInfo.objects.select_for_update().get_or_create( |
346 | 344 |
brand_id=brand.brand_id, |
347 | 345 |
model_id=model.model_id, |
348 |
- ymd=y, |
|
346 |
+ ymd=ymd[:4], |
|
349 | 347 |
) |
350 | 348 |
mssi.model_name = model.model_name |
351 | 349 |
mssi.num += 1 |
@@ -5,8 +5,10 @@ import logging |
||
5 | 5 |
import requests |
6 | 6 |
from django.conf import settings |
7 | 7 |
from django.db import transaction |
8 |
+from django_models_ext import ProvinceModelMixin, ProvinceShortModelMixin |
|
8 | 9 |
from django_six import CompatibilityBaseCommand, close_old_connections |
9 | 10 |
|
11 |
+from statistic.models import ConsumeProvinceSaleStatisticInfo |
|
10 | 12 |
from utils.redis.connect import r |
11 | 13 |
from utils.redis.rkeys import MINI_PROGRAM_GIS_LIST |
12 | 14 |
|
@@ -21,10 +23,10 @@ class Command(CompatibilityBaseCommand): |
||
21 | 23 |
|
22 | 24 |
while True: |
23 | 25 |
# r.rpushjson('TEMPLET_CMD_KEY', { |
26 |
+ # 'brand_id': 'brand_id', |
|
24 | 27 |
# 'lat': .0, |
25 | 28 |
# 'lon': .0, |
26 |
- # 'ymd': 0, |
|
27 |
- # 'ym': 0, |
|
29 |
+ # 'ymd': '20121212', |
|
28 | 30 |
# }) |
29 | 31 |
k, v = r.blpopjson(MINI_PROGRAM_GIS_LIST, 60) |
30 | 32 |
if v: |
@@ -40,8 +42,50 @@ class Command(CompatibilityBaseCommand): |
||
40 | 42 |
logger.info(e.message) |
41 | 43 |
if gisinfo.get('error') != 0: |
42 | 44 |
continue |
43 |
- ymd = v.get('ymd', 0) |
|
44 |
- ym = v.get('ym', 0) |
|
45 |
+ |
|
45 | 46 |
zh1 = gisinfo.get('data', {}).get('zh1', '') |
46 | 47 |
|
48 |
+ if not zh1: |
|
49 |
+ continue |
|
50 |
+ |
|
51 |
+ province_code = ProvinceModelMixin.PROVINCE_NAME_CODE_DICT.get(zh1) |
|
52 |
+ |
|
53 |
+ if not province_code: |
|
54 |
+ continue |
|
55 |
+ |
|
56 |
+ brand_id = v.get('brand_id', '') |
|
57 |
+ ymd = v.get('ymd', '') |
|
58 |
+ |
|
59 |
+ # [消费者维度]省份销量统计 |
|
60 |
+ # 日 |
|
61 |
+ cpssi, _ = ConsumeProvinceSaleStatisticInfo.objects.select_for_update().get_or_create( |
|
62 |
+ brand_id=brand_id, |
|
63 |
+ province_code=province_code, |
|
64 |
+ ymd=ymd, |
|
65 |
+ ) |
|
66 |
+ if not cpssi.province_name: |
|
67 |
+ cpssi.province_name = ProvinceShortModelMixin.PROVINCE_CODE_NAME_DICT.get(province_code) |
|
68 |
+ cpssi.num += 1 |
|
69 |
+ cpssi.save() |
|
70 |
+ # 月 |
|
71 |
+ cpssi, _ = ConsumeProvinceSaleStatisticInfo.objects.select_for_update().get_or_create( |
|
72 |
+ brand_id=brand_id, |
|
73 |
+ province_code=province_code, |
|
74 |
+ ymd=ymd[:6], |
|
75 |
+ ) |
|
76 |
+ if not cpssi.province_name: |
|
77 |
+ cpssi.province_name = ProvinceShortModelMixin.PROVINCE_CODE_NAME_DICT.get(province_code) |
|
78 |
+ cpssi.num += 1 |
|
79 |
+ cpssi.save() |
|
80 |
+ # 年 |
|
81 |
+ cpssi, _ = ConsumeProvinceSaleStatisticInfo.objects.select_for_update().get_or_create( |
|
82 |
+ brand_id=brand_id, |
|
83 |
+ province_code=province_code, |
|
84 |
+ ymd=ymd[:4], |
|
85 |
+ ) |
|
86 |
+ if not cpssi.province_name: |
|
87 |
+ cpssi.province_name = ProvinceShortModelMixin.PROVINCE_CODE_NAME_DICT.get(province_code) |
|
88 |
+ cpssi.num += 1 |
|
89 |
+ cpssi.save() |
|
90 |
+ |
|
47 | 91 |
close_old_connections() |
@@ -138,9 +138,7 @@ def clerk_sale_submit_api(request): |
||
138 | 138 |
|
139 | 139 |
# TODO: Make statistic async |
140 | 140 |
if not sci: |
141 |
- ymd = int(tc.local_string(format='%Y%m%d')) |
|
142 |
- ym = int(tc.local_string(format='%Y%m')) |
|
143 |
- y = int(tc.local_string(format='%Y')) |
|
141 |
+ ymd = tc.local_string(format='%Y%m%d') |
|
144 | 142 |
|
145 | 143 |
# 日销量统计 |
146 | 144 |
ssi, _ = SaleStatisticInfo.objects.select_for_update().get_or_create( |
@@ -152,14 +150,14 @@ def clerk_sale_submit_api(request): |
||
152 | 150 |
# 月销量统计 |
153 | 151 |
ssi, _ = SaleStatisticInfo.objects.select_for_update().get_or_create( |
154 | 152 |
brand_id=brand.brand_id, |
155 |
- ymd=ym, |
|
153 |
+ ymd=ymd[:6], |
|
156 | 154 |
) |
157 | 155 |
ssi.num += 1 |
158 | 156 |
ssi.save() |
159 | 157 |
# 年销量统计 |
160 | 158 |
ssi, _ = SaleStatisticInfo.objects.select_for_update().get_or_create( |
161 | 159 |
brand_id=brand.brand_id, |
162 |
- ymd=y, |
|
160 |
+ ymd=ymd[:4], |
|
163 | 161 |
) |
164 | 162 |
ssi.num += 1 |
165 | 163 |
ssi.save() |
@@ -215,7 +213,7 @@ def clerk_sale_submit_api(request): |
||
215 | 213 |
pssi, _ = ProvinceSaleStatisticInfo.objects.select_for_update().get_or_create( |
216 | 214 |
brand_id=brand.brand_id, |
217 | 215 |
province_code=distributor.distributor_province_code, |
218 |
- ymd=ym, |
|
216 |
+ ymd=ymd[:6], |
|
219 | 217 |
) |
220 | 218 |
pssi.province_name = distributor.distributor_province_name |
221 | 219 |
pssi.num += 1 |
@@ -224,7 +222,7 @@ def clerk_sale_submit_api(request): |
||
224 | 222 |
pssi, _ = ProvinceSaleStatisticInfo.objects.select_for_update().get_or_create( |
225 | 223 |
brand_id=brand.brand_id, |
226 | 224 |
province_code=distributor.distributor_province_code, |
227 |
- ymd=y, |
|
225 |
+ ymd=ymd[:4], |
|
228 | 226 |
) |
229 | 227 |
pssi.province_name = distributor.distributor_province_name |
230 | 228 |
pssi.num += 1 |
@@ -254,7 +252,7 @@ def clerk_sale_submit_api(request): |
||
254 | 252 |
sssi, _ = SaleclerkSaleStatisticInfo.objects.select_for_update().get_or_create( |
255 | 253 |
brand_id=brand.brand_id, |
256 | 254 |
clerk_id=clerk.clerk_id, |
257 |
- ymd=ym, |
|
255 |
+ ymd=ymd[:6], |
|
258 | 256 |
) |
259 | 257 |
sssi.distributor_id = distributor.distributor_id |
260 | 258 |
sssi.province_name = distributor.distributor_province_name |
@@ -265,7 +263,7 @@ def clerk_sale_submit_api(request): |
||
265 | 263 |
sssi, _ = SaleclerkSaleStatisticInfo.objects.select_for_update().get_or_create( |
266 | 264 |
brand_id=brand.brand_id, |
267 | 265 |
clerk_id=clerk.clerk_id, |
268 |
- ymd=y, |
|
266 |
+ ymd=ymd[:4], |
|
269 | 267 |
) |
270 | 268 |
sssi.distributor_id = distributor.distributor_id |
271 | 269 |
sssi.province_name = distributor.distributor_province_name |
@@ -5,11 +5,14 @@ from __future__ import division |
||
5 | 5 |
import xlrd |
6 | 6 |
from django.conf import settings |
7 | 7 |
from pysnippets.strsnippets import strip |
8 |
+from TimeConvert import TimeConvert as tc |
|
8 | 9 |
|
9 |
-from mch.models import BrandInfo, DistributorInfo, ModelInfo |
|
10 |
+from mch.models import BrandInfo, ConsumeInfoSubmitLogInfo, DistributorInfo, ModelInfo |
|
10 | 11 |
from statistic.models import (ConsumeDistributorSaleStatisticInfo, ConsumeModelSaleStatisticInfo, |
11 | 12 |
ConsumeProvinceSaleStatisticInfo, ConsumeSaleStatisticInfo, DistributorSaleStatisticInfo, |
12 | 13 |
ModelSaleStatisticInfo, ProvinceSaleStatisticInfo, SaleStatisticInfo) |
14 |
+from utils.redis.connect import r |
|
15 |
+from utils.redis.rkeys import MINI_PROGRAM_GIS_LIST |
|
13 | 16 |
|
14 | 17 |
|
15 | 18 |
PROVINCE_LIST = { |
@@ -196,3 +199,14 @@ def fill_ym(): |
||
196 | 199 |
) |
197 | 200 |
ssi.num += o.num |
198 | 201 |
ssi.save() |
202 |
+ |
|
203 |
+ |
|
204 |
+def refreshp(): |
|
205 |
+ logs = ConsumeInfoSubmitLogInfo.objects.filter(test_user=False) |
|
206 |
+ for log in logs: |
|
207 |
+ r.rpushjson(MINI_PROGRAM_GIS_LIST, { |
|
208 |
+ 'brand_id': log.brand_id, |
|
209 |
+ 'lat': log.lat, |
|
210 |
+ 'lon': log.lon, |
|
211 |
+ 'ymd': tc.local_string(tc.to_local_datetime(log.created_at), format='%Y%m%d'), |
|
212 |
+ }) |
@@ -241,8 +241,8 @@ def ymdtj(brand_id, ymd, lastymd): |
||
241 | 241 |
salesmen = SaleclerkSaleStatisticInfo.objects.filter(brand_id=brand_id, ymd=ymd, status=True).order_by('-num')[:20] |
242 | 242 |
salesmen = [s.data for s in salesmen] |
243 | 243 |
|
244 |
- # [经销商维度] 统计周期内省份销量排行数据,请按顺序返回 |
|
245 |
- provinces = ProvinceSaleStatisticInfo.objects.filter(brand_id=brand_id, ymd=ymd, status=True) |
|
244 |
+ # [收费者维度] 统计周期内省份销量排行数据,请按顺序返回 |
|
245 |
+ provinces = ConsumeProvinceSaleStatisticInfo.objects.filter(brand_id=brand_id, ymd=ymd, status=True) |
|
246 | 246 |
provinces = [p.data for p in provinces] |
247 | 247 |
|
248 | 248 |
return { |